﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RadarA
{
    class RadaA1
    {
        public static bool TatMoVongTron;
        bool catchedTargetFlag; // kiểm tra vẽ màn hình radar để làm apdate
        public bool changeTargetFlag;  // kiểm tra màn hình vẽ được chưa
        public int targetCatched = 0;    // so hieu cua muc tieu can bam
        public Image baseImageRadarScan;    //tao nen man hinh radar
        public bool clockwiseScan = true;  //chieu quet cua radar
        static int _size;   //size cua man hinh chinh radar
        public Image outputImageRadarScan;      //anh radar tai 1 thoi diem voi cac muc tieu tren man cập nhật mt v
        public double maxAngle = 60;           //goc ngang cao nhat cua radar. mac dinh la 60 do
        public int _az = 0;  //goc quet cua radar hien thoi

        public int Sovongtron; // ve số vòng tròn
        //ba diem xac dinh canh song cua radar
        public PointF _pt;     //trung tam canh song - goc phuong vi cua radar
        public PointF _pt2;     //goc phuong vi trung tam -20 
        public PointF _pt3;     //goc phuong vi trung tam +20
        Timer t; // định thời cho toàn hệ thống
        //Color _lineColor = Color.FromArgb(0, 255, 0);// vẽ màu đường quét
        Color _lineColor = Color.FromArgb(0, 255, 0);// vẽ màu đường quét
        Color newcolor = Color.FromArgb(0, 255, 230);
        Graphics g = null;  // công cụ vẽ
        public List<MucTieu> TargetList = new List<MucTieu>();
        private ToaDo currentObject;
        public static bool TatmoAnten;//tắt mở ăn ten quay
        public static int soGiaymotVong; //so giây cho 1 vòng quây

        PointF _huong;
        PointF CenterPoint;
        public RadaA1(int diameter, int sovong)
        {
            //Khoi tao radar voi size cua man scan = diameter, chiều ngang pictireBox


            _size = diameter; // chiều ngang pictireBox
            Sovongtron = sovong;
            //Khoi tao cac anh nen voi thong so da cho
            if (Sovongtron == 3)
            {
                CreateBaseImage3();// vẽ 3 vòng tròn và các đường line
            }
            if (Sovongtron == 5)
            {
                CreateBaseImage();// vẽ 3 vòng tròn và các đường line
            }
            if (Sovongtron == 6)
            {
                CreateBaseImage6();// vẽ 3 vòng tròn và các đường line
            }

            //Tao anh dau ra cua radar
            Draw();  // vẽ điểm, màn hình... theo timer
            // khoi tao bo dem thoi gian de ve anh 
            t = new Timer();
            t.Enabled = true;
            t.Tick += new EventHandler(t_Tick);
            t.Interval = 40;
        }
        void t_Tick(object sender, EventArgs e)
        {
            //neu khong co muc tieu bam
            if (targetCatched == 0)
            {

                // tang hoac giam goc quet
                if (clockwiseScan)
                {
                    _az++;
                }
                else
                {
                    _az--;
                }
                // reset goc phuong vi
                // neu khong xuat hien loi OverflowException
                if (_az >= 360)
                    _az = 0;

                // tao 3 diem de xac dinh canh song radar
                _pt = AzRg2XY(_az, _size / 2);
                _pt2 = AzRg2XY(_az - 20, _size / 2);
                _pt3 = AzRg2XY(_az + 20, _size / 2);

                //MainForm.culy = _pt3.X;
                //MainForm.phuongvi = _pt3.Y;

                // ve lai anh dau ra

                Draw();
            }

            // neu co muc tieu bam
            else
            {

                foreach (MucTieu item in TargetList)
                {
                    if (item.ID == targetCatched)
                        _az = getAzimuth(item._current);
                }

                _pt = AzRg2XY(_az, _size / 2);
                _pt2 = AzRg2XY(_az - 20, _size / 2);
                _pt3 = AzRg2XY(_az + 20, _size / 2);

                Draw();
            }
        }

        private PointF AzRg2XY(int azimuth, int Rg)
        {
            //chuyen goc phuong vi sang goc theo truc X
            double angle = (270d + (double)azimuth);

            // chuyen sang radian
            angle *= 0.0174532925d;

            double r, x, y;

            // tinh x va y theo size cua man hinh scan radar co san
            r = Rg;

            x = (((double)_size * 0.5d) + (r * Math.Cos(angle)));
            y = (((double)_size * 0.5d) + (r * Math.Sin(angle)));

            return new PointF((float)x, (float)y);
        }
        void CreateBaseImage()
        {
            // tao thuc the drawing
            Image i = new Bitmap(_size, _size);
            if (g != null)
            {
                g.Dispose();
            }
            else
            {
                g = Graphics.FromImage(i);
            }
            //Graphics g = Graphics.FromImage(i);
            Pen p = new Pen(_lineColor);
            //lam anh dep hon
            g.CompositingQuality = CompositingQuality.HighQuality;
            g.InterpolationMode = InterpolationMode.Bicubic;
            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.TextRenderingHint = TextRenderingHint.AntiAlias;
            // ve anh nen cua anh radar scan

            g.DrawEllipse(p, 0, 0, _size - 1, _size - 1);
            // ve cac vong tron ( o day la 5 vong tron)
            int interval = _size / Sovongtron;
            Font ab = new Font("Arial", 10);
            for (int j = 1; j < Sovongtron; j++)
            {
                int interval1 = interval * j;
                g.DrawEllipse(p, (_size - interval1) / 2, (_size - interval1) / 2, interval1, interval1);
                //Font ab = new Font("Arial", 10);
                //g.DrawString((30 - 6 * j).ToString() + "0", ab, Brushes.Red, interval1 / 2, _size / 2);
                //g.DrawString((30 - 6 * j).ToString() + "0", ab, Brushes.Red, _size - interval1 / 2 - 15, _size / 2);
                if (j == 1)
                {
                    g.DrawString("120", ab, Brushes.Red, _size / 2, 30);
                }
                if (j == 2)
                {
                    g.DrawString("90", ab, Brushes.Red, _size / 2, 80);
                }
                if (j == 3)
                {
                    g.DrawString("60", ab, Brushes.Red, _size / 2, 130);
                }
                if (j == 4)
                {
                    g.DrawString("30", ab, Brushes.Red, _size / 2, 180);
                }
            }
            ve12doan();

            Font abc = new Font("Arial", 10);

            g.DrawString("W", abc, Brushes.Red, 0, _size / 2);
            g.DrawString("N", abc, Brushes.Red, _size / 2, 0);
            g.DrawString("E", abc, Brushes.Red, _size - 15, _size / 2);
            g.DrawString("S", abc, Brushes.Red, _size / 2, _size - 15);
            // xoa anh ve
            g.Dispose();
            // update the base image
            baseImageRadarScan = i;
        }
        public void CreateBaseImage3()
        {
            // tao thuc the drawing
            Image i = new Bitmap(_size, _size);
            if (g != null)
            {
                g.Dispose();
            }
            else
            {
                g = Graphics.FromImage(i);
            }
            //Graphics g = Graphics.FromImage(i);
            Pen p = new Pen(_lineColor);
            //lam anh dep hon
            g.CompositingQuality = CompositingQuality.HighQuality;
            g.InterpolationMode = InterpolationMode.Bicubic;
            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.TextRenderingHint = TextRenderingHint.AntiAlias;
            // ve anh nen cua anh radar scan

            //g.DrawEllipse(p, 0, 0, _size - 1, _size - 1);
            p.Color = Color.White;
            //_size = _size - 10;
            g.DrawEllipse(p, 0, 0, _size - 1, _size - 1);
            //ve mau nen cho radar
            g.FillEllipse(new LinearGradientBrush(new Point((int)(_size / 2), 0), new Point((int)(_size / 2), _size - 1), Color.Blue, Color.Blue), 0, 0, _size - 1, _size -1);
            // ve cac vong tron ( o day la 5 vong tron)
            int interval = _size / 3;
            Font ab = new Font("Arial", 10);
            p.Color = Color.White;

            if (!tatmovongtron)
            {
                g.DrawEllipse(p, (_size - interval) / 2, (_size - interval) / 2, interval, interval);
                for (int j = 1; j < 3; j++)
                {
                    int interval1 = interval * j;
                    g.DrawEllipse(p, (_size - interval1) / 2, (_size - interval1) / 2, interval1, interval1);
                }
            }

            ve12doan();
            Font abc = new Font("Arial", 10);

            g.DrawString("W", abc, Brushes.Red, 0, _size / 2);
            g.DrawString("N", abc, Brushes.Red, _size / 2, 0);
            g.DrawString("E", abc, Brushes.Red, _size - 15, _size / 2);
            g.DrawString("S", abc, Brushes.Red, _size / 2, _size - 15);
            // xoa anh ve
            g.Dispose();
            // update the base image
            baseImageRadarScan = i;
        }
        void ve12doan()
        {
            Pen p = new Pen(_lineColor);
            Font ab = new Font("Arial", 10);
            // ve truc Ox va truc Oy
            g.DrawLine(p, new Point(0, (int)(_size / 2)), new Point(_size - 1, (int)(_size / 2)));
            g.DrawLine(p, new Point((int)(_size / 2), 0), new Point((int)(_size / 2), _size - 1));

            _huong = huong(30, _size);
            g.DrawLine(p, new Point((int)_size / 2, _size / 2), new Point(Convert.ToInt16(_huong.X), Convert.ToInt16(_huong.Y)));
            g.DrawString("30", ab, Brushes.Red, new Point(Convert.ToInt16(_huong.X), Convert.ToInt16(_huong.Y) - 12)); //337, 20);

            _huong = huong(60, _size);
            g.DrawLine(p, new Point((int)_size / 2, _size / 2), new Point(Convert.ToInt16(_huong.X), Convert.ToInt16(_huong.Y)));
            g.DrawString("60", ab, Brushes.Red, Convert.ToInt16(_huong.X), Convert.ToInt16(_huong.Y) - 8);//418, 105);

            _huong = huong(120, _size);
            //120 do
            g.DrawLine(p, new Point((int)_size / 2, _size / 2), new Point(Convert.ToInt16(_huong.X), Convert.ToInt16(_huong.Y)));
            g.DrawString("120", ab, Brushes.Red, Convert.ToInt16(_huong.X), Convert.ToInt16(_huong.Y));//416, 333);

            _huong = huong(150, _size);
            //150 d0
            g.DrawLine(p, new Point((int)_size / 2, _size / 2), new Point(Convert.ToInt16(_huong.X), Convert.ToInt16(_huong.Y)));
            g.DrawString("150", ab, Brushes.Red, Convert.ToInt16(_huong.X), Convert.ToInt16(_huong.Y));//333, 417);

            _huong = huong(210, _size);
            //210 do
            g.DrawLine(p, new Point((int)_size / 2, _size / 2), new Point(Convert.ToInt16(_huong.X), Convert.ToInt16(_huong.Y)));
            g.DrawString("210", ab, Brushes.Red, Convert.ToInt16(_huong.X) - 15, Convert.ToInt16(_huong.Y) + 2);//93, 419);

            _huong = huong(240, _size);
            //240
            g.DrawLine(p, new Point((int)_size / 2, _size / 2), new Point(Convert.ToInt16(_huong.X), Convert.ToInt16(_huong.Y)));
            g.DrawString("240", ab, Brushes.Red, Convert.ToInt16(_huong.X) - 20, Convert.ToInt16(_huong.Y) - 10);//4, 327);

            _huong = huong(300, _size);
            //300
            g.DrawLine(p, new Point((int)_size / 2, _size / 2), new Point(Convert.ToInt16(_huong.X), Convert.ToInt16(_huong.Y)));
            g.DrawString("300", ab, Brushes.Red, Convert.ToInt16(_huong.X) - 25, Convert.ToInt16(_huong.Y) - 7);//8, 96);

            _huong = huong(330, _size);
            //330
            g.DrawLine(p, new Point((int)_size / 2, _size / 2), new Point(Convert.ToInt16(_huong.X), Convert.ToInt16(_huong.Y)));
            g.DrawString("330", ab, Brushes.Red, Convert.ToInt16(_huong.X) - 20, Convert.ToInt16(_huong.Y) - 10);//93, 15);
        }
        void CreateBaseImage6()
        {
            // tao thuc the drawing
            Image i = new Bitmap(_size, _size);
            if (g != null)
            {
                g.Dispose();
            }
            else
            {
                g = Graphics.FromImage(i);
            }
            //Graphics g = Graphics.FromImage(i);
            Pen p = new Pen(_lineColor);
            //lam anh dep hon
            g.CompositingQuality = CompositingQuality.HighQuality;
            g.InterpolationMode = InterpolationMode.Bicubic;
            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.TextRenderingHint = TextRenderingHint.AntiAlias;
            // ve anh nen cua anh radar scan

            g.DrawEllipse(p, 0, 0, _size - 1, _size - 1);
            // ve cac vong tron ( o day la 5 vong tron)
            int interval = _size / 6;
            Font ab = new Font("Arial", 10);
            for (int j = 1; j < 6; j++)
            {
                int interval1 = interval * j;
                g.DrawEllipse(p, (_size - interval1) / 2, (_size - interval1) / 2, interval1, interval1);
                //Font ab = new Font("Arial", 10);
                //g.DrawString((30 - 6 * j).ToString() + "0", ab, Brushes.Red, interval1 / 2, _size / 2);
                //g.DrawString((30 - 6 * j).ToString() + "0", ab, Brushes.Red, _size - interval1 / 2 - 15, _size / 2);
                if (j == 1)
                {
                    g.DrawString("50", ab, Brushes.Red, 225, 30);
                }
                if (j == 2)
                {
                    g.DrawString("40", ab, Brushes.Red, 225, 65);
                }
                if (j == 3)
                {
                    g.DrawString("30", ab, Brushes.Red, 225, 105);
                }
                if (j == 4)
                {
                    g.DrawString("20", ab, Brushes.Red, 225, 145);
                }
                if (j == 5)
                {
                    g.DrawString("10", ab, Brushes.Red, 225, 185);
                }
            }
            ve12doan();

            Font abc = new Font("Arial", 10);

            g.DrawString("W", abc, Brushes.Red, 0, _size / 2);
            g.DrawString("N", abc, Brushes.Red, _size / 2, 0);
            g.DrawString("E", abc, Brushes.Red, _size - 15, _size / 2);
            g.DrawString("S", abc, Brushes.Red, _size / 2, _size - 15);
            // xoa anh ve
            g.Dispose();
            // update the base image
            baseImageRadarScan = i;
        }

        void Draw()  // khong làm gì chỉ để gọi thực thi trong cùng lớp
        {
            Image scanImage; // đối tượng vẽ radar
            if (!catchedTargetFlag) // kiểm tra vẽ hay chưa
                scanImage = (Image)baseImageRadarScan.Clone();
            else
            {
                if (changeTargetFlag)
                    scanImage = (Image)baseImageRadarScan.Clone();
                else
                    scanImage = outputImageRadarScan;
            }
            //

            Graphics scanGraphic = Graphics.FromImage(scanImage);  // vẽ hình 2 chiều radar đối tượng scanImage truyền để vẽ


            GraphicsPath gp = new GraphicsPath(FillMode.Winding);  // vẽ kiểu ưinding

            if (!catchedTargetFlag && _pt2.Y != 0 && _pt2.Y != _size / 2 && _pt2.Y != _size)  //nếu chạy lần đầu tiên thì vẽ 
            {
                //ve canh song radar

                gp.AddLine(new PointF((float)(_size / 2), (float)(_size / 2)), _pt2);// add vẽ vệt quét

                // chùm tia quét
                //gp.AddCurve(new PointF[] { _pt2, AzRg2XY(_az - 20, _size / 2), AzRg2XY(_az - 10, _size / 2), _pt, AzRg2XY(_az + 10, _size / 2), AzRg2XY(_az + 20, _size / 2), _pt3 });
                //gp.AddLine(_pt3, new PointF((float)(_size / 2), (float)(_size / 2)));
                PathGradientBrush pgb = new PathGradientBrush(gp);// định nghịa đôi tượng vẽ 2D
                pgb.CenterPoint = _pt3;// ve điểm
                pgb.CenterColor = Color.FromArgb(128, _lineColor); // vẽ đường line
                pgb.SurroundColors = new Color[] { Color.Red };// chỉnh màu nền
                scanGraphic.FillPath(pgb, gp);  // đổ dữ liệu hình ảnh gp cho pgb
                // ve tia quet
                if (TatmoAnten)
                {
                    scanGraphic.DrawLine(new Pen(_lineColor), new PointF((float)(_size / 2), (float)(_size / 2)), _pt3);// vẽ tắt mở đường quét
                }

            }
            //tinh sin cua goc ngang cao nhat
            currentObject = null;
            double max_angle = maxAngle * 0.0174532925d;      //doi sang radian  d là đơn vị radian
            CenterPoint = new PointF(_size / 2, _size / 2);

            foreach (MucTieu item in TargetList)  // nếu danh sách mục tiêu trên màn hình
            {
                //item.DrawItem(this, scanGraphic,pathIcon);  // vẽ mục tiê với đường dẫn

                //if (currentObject == null)
                //{
                //    currentObject = item._current;
                //}
                //currentObject = item._current; // mục tiêu hiện tại

                //if (_az + 20 > 360)
                //{
                //    if (getAzimuth(item._current) < 360 && getAzimuth(item._current) > getAzimuth(_pt2) && (getRange(item._current) * Math.Sin(max_angle)) > item._current.Z && getRange(item._current) < _size / 2)
                //    {
                //        item.DrawItem(this, scanGraphic,pathIcon);
                //        currentObject = null;
                //    }
                //}
                //else
                //{
                //    if (getAzimuth(item._current) < getAzimuth(_pt3) && getAzimuth(item._current) > getAzimuth(_pt2) && (getRange(item._current) * Math.Sin(max_angle)) > item._current.Z && getRange(item._current) < _size / 2)
                //    {
                //        item.DrawItem(this, scanGraphic, pathIcon);
                //    }
                //}
                int abc = checkmousemove(Convert.ToInt16(item._current.X), Convert.ToInt16(item._current.Y), _size);
                if (abc < 235)
                {
                    item.DrawItem(this, scanGraphic, _size);
                }

                //if (clsCommons.bonhao && clsCommons.showBonhao)
                //{
                //    if (Convert.ToInt16(getRange(item._current)) >= 0 && Convert.ToInt16(getRange(item._current))<=5)
                //    {
                //        clsCommons.showBonhao = false;
                //    }
                //    else
                //    {                        
                //        item.DrawItem(this, scanGraphic, _size);
                //    }
                //}
                //else
                //{
                //    if (getAzimuth(item._current) < 360 && getAzimuth(item._current) > getAzimuth(_pt2) && (getRange(item._current) * Math.Sin(max_angle)) > item._current.Z && getRange(item._current) < _size / 2)
                //    {
                //        item.DrawItem(this, scanGraphic, _size);// tính toán hướng vẽ lai mục tiêu theo đường dãn hình
                //    }
                //}

                if (getAzimuth(item._current) < 360 && getAzimuth(item._current) > getAzimuth(_pt2) && (getRange(item._current) * Math.Sin(max_angle)) > item._current.Z && getRange(item._current) < _size / 2)
                {
                    item.DrawItem(this, scanGraphic, _size);// tính toán hướng vẽ lai mục tiêu theo đường dãn hình
                }
                //item.DrawItem(this, scanGraphic, _size);// tính toán hướng vẽ lai mục tiêu theo đường dãn hình
            }




            // giai phong tai nguyen
            scanGraphic.Dispose();

            // goi ham update anh theo timer
            OnImageUpdate(scanImage);
            // xét lại trạng thái ve rồi hay chưa để làm
            if (targetCatched == 0)
                catchedTargetFlag = false;
            else
            {
                catchedTargetFlag = true;
                changeTargetFlag = false;
            }
        }

        private int checkmousemove(int _x, int _y, int _size)
        {
            double r, x, y;
            r = _size * 0.5d;//ban kinh duong tron
            //xac dinh toa do so voi tam
            x = _x - r;
            y = _y - r;
            double canh_huyen = Math.Sqrt(x * x + y * y);
            return Convert.ToInt16(canh_huyen);
        }
        //hàm này vẽ số(hướng) trên mỗi đầu thanh vẽ
        public PointF huong(int azimuth, int widthPictrueBox)
        {
            int _size = widthPictrueBox;
            //chuyen goc phuong vi sang goc theo truc X
            double angle = (270d + (double)azimuth);

            // chuyen sang radian
            angle *= 0.0174532925d;

            double r, x, y;

            // tinh x va y theo size cua man hinh scan radar co san
            r = _size * 0.5;

            //_size = pictureBox1.Width;

            x = (((double)_size * 0.5d) + (r * Math.Cos(angle)));
            y = (((double)_size * 0.5d) + (r * Math.Sin(angle)));

            return new PointF((float)x, (float)y);
        }
        // lay cu ly cua mot toa do da cho
        public static double getRange(ToaDo td)
        {
            double r, x, y;
            r = _size * 0.5d;//ban kinh duong tron
            //xac dinh toa do so voi tam
            x = td.X - r;
            y = td.Y - r;
            double canh_huyen = Math.Sqrt(x * x + y * y);
            return canh_huyen;
        }
        public static double getRange(int _x, int _y, int size)
        {
            double r, x, y;
            r = size * 0.5d;//ban kinh duong tron
            //xac dinh toa do so voi tam
            x = _x - r;
            y = _y - r;
            double canh_huyen = Math.Sqrt(x * x + y * y);
            return Convert.ToInt16(canh_huyen) / 8;
        }

        private int getAzimuth(PointF DiemCurrent)  //tính điểm hiện tại
        {
            double r, x, y;
            r = _size * 0.5d;//ban kinh duong tron
            //xac dinh toa do so voi tam
            x = DiemCurrent.X - r;
            y = DiemCurrent.Y - r;
            double canh_huyen = Math.Sqrt(x * x + y * y);
            //tinh goc so voi truc x
            double angle = Math.Acos(x / canh_huyen);
            //doi sang do.
            angle = angle / 0.0174532925d;

            if (y < 0)
            {
                angle = 360d - angle;
            }
            //chuyen sang goc so voi truc. y - Phuong BAC'

            double azimuth = angle - 270d;
            if (azimuth < 0) azimuth = azimuth + 360d;
            return (int)azimuth;
        }

        private void OnImageUpdate(Image i)
        {
            if (ImageUpdate != null)
                ImageUpdate(this, new ImageUpdateEventArgs(i));
        }
        public event ImageUpdateHandler ImageUpdate;
        public bool pathIcon { get; set; }

        public int DrawScanInterval
        {
            //Khoang thoi gian giua 2 lan quet, cang tang thi duong quet cang cham
            get
            {
                return t.Interval;
            }
            set
            {
                if (value > 0)
                    t.Interval = value;
            }
        }
        public Image Image
        {
            get
            {
                return outputImageRadarScan;
            }
        }



        public static int getAzimuth(ToaDo DiemPoint)  // hàm tính lại tọa độ của 1 điểm
        {
            double r, x, y;
            r = _size * 0.5d;//ban kinh duong tron
            //xac dinh toa do so voi tam
            x = DiemPoint.X - r;
            y = DiemPoint.Y - r;
            double canh_huyen = Math.Sqrt(x * x + y * y);  // Cạnh huyền là hướng
            //tinh goc so voi truc x
            double angle = Math.Acos(x / canh_huyen);
            //doi sang do.
            angle = angle / 0.0174532925d;

            if (y < 0)  // nếu y nằm bên trái màn hình
            {
                angle = 360d - angle;  // trừ số độ hiện tại
            }
            //chuyen sang goc so voi truc. y - Phuong BAC'

            double azimuth = angle - 270d;// góc phương vị
            if (azimuth < 0) azimuth = azimuth + 360d;
            return (int)azimuth;
        }

        //them cac muc tieu vao list muc tieu cua radar
        public void AddItem(MucTieu item)
        {
            bool bFlag = true;

            for (int i = 0; i < TargetList.Count; i++)
            {
                if (TargetList[i].ID == item.ID)
                {
                    TargetList[i] = item;
                    bFlag = false;
                }

            }

            if (bFlag)
                TargetList.Add(item);

            Draw();
        }

        internal bool checkMap(int toadoX, int toadoY)
        {
            bool isMap = false;
            if (currentObject != null)
            {
                if ((Convert.ToInt16(currentObject.X) - 10) <= toadoX && (Convert.ToInt16(currentObject.X) + 10) >= toadoX && (Convert.ToInt16(currentObject.Y) - 10) <= toadoY && (Convert.ToInt16(currentObject.Y) + 10) >= toadoY)
                {
                    isMap = true;
                }
            }

            return isMap;
        }



        public bool tatmovongtron { get; set; }
    }
    public delegate void ImageUpdateHandler(object sender, ImageUpdateEventArgs e);
    public class ImageUpdateEventArgs : EventArgs
    {
        Image _image;

        public Image Image
        {
            get
            {
                return _image;
            }
        }

        public ImageUpdateEventArgs(Image i)
        {
            _image = i;
        }

    }
}
